package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.AddressMapper;
import cn.tedu.egmvc2.pojo.entity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @RequestMapping("insert")
    public String insert(Address address) {
        Address address1 = new Address();
        BeanUtils.copyProperties(address, address1);
        addressMapper.insert(address1);
        return "插入成功";
    }
    @RequestMapping("select")
    public List<Address> select() {

        return addressMapper.selectAll();
    }
    @RequestMapping("delete")
    public String delete(Integer id) {
        addressMapper.deleteById(id);
        return "删除成功";
    }
    @RequestMapping("update")
    public String update(Address address) {
        addressMapper.update(address);
        return "更新成功";
    }

}
